package org.window;

import com.scm.all.export.*;
import com.scm.all.pfunc.MemoryCallBack;
import com.scm.all.struct.TagMemoryDataX86;
import com.scm.x64.export.MemoryOperationUtilsX64;
import com.scm.x86.export.MemoryOperationUtilsX86;
import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.EventHandler;
import javafx.scene.control.Button;
import javafx.scene.control.TableView;
import javafx.scene.image.Image;
import javafx.scene.input.MouseEvent;
import javafx.scene.layout.*;
import org.apache.commons.lang3.StringUtils;
import org.mapdb.DB;
import org.mapdb.DBMaker;
import org.mapdb.unsafe.DBMakerUnsafe;
import org.openProcess.StageWindowsProcessAndListView;
import org.showData.StageWindowShow;


import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

/**
 * 首次搜索
 */
public class PaneAndHBoxFrameAndColumnVBoxAndHBoxAndButtonSearchOne {
    public static Button button = new Button();
    public static List<TagMemoryDataX86> resultsMap = new ArrayList<>();
    public static byte[] data;
    public static void init(){
        button.setText("首次搜索");
        button.setPrefWidth(80);
        button.setPrefHeight(30);
        button.setBackground(new Background(new BackgroundImage(new Image("bgk.jpg"), BackgroundRepeat.NO_REPEAT ,BackgroundRepeat.REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
        button.setStyle("-fx-text-fill: #ffffff");
        button.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                button.setBackground(new Background(new BackgroundImage(new Image("bgk2.jpg"), BackgroundRepeat.NO_REPEAT ,BackgroundRepeat.REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
            }
        });
        button.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                button.setBackground(new Background(new BackgroundImage(new Image("bgk.jpg"), BackgroundRepeat.NO_REPEAT ,BackgroundRepeat.REPEAT, BackgroundPosition.CENTER, BackgroundSize.DEFAULT)));
            }
        });
        button.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if(!StringUtils.equals(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"")){
                    StageWindowShow.stage.hide();
                    PaneAndHBoxFrameAndProgressBar.progressBar.setProgress(-1);
                    PaneAndHBoxFrameAndColumnAndTableView.data = FXCollections.observableArrayList();
                    resultsMap.clear();
                    switch (PaneAndHBoxFrameAndColumnVBoxAndPaneAndHBoxAndComCoBox.comboBox.getSelectionModel().getSelectedIndex()){
                        case 0:data = ByteUtils.getObjectTypeToByte((char)PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText().charAt(0),"char");break;
                        case 1:data = ByteUtils.getObjectTypeToByte((short)Short.parseShort(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"short");break;
                        case 2:data = ByteUtils.getObjectTypeToByte((int) Integer.parseInt(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"int");break;
                        case 3:data = ByteUtils.getObjectTypeToByte((long) Long.parseLong(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"long");break;
                        case 4:data = ByteUtils.getObjectTypeToByte((float) Float.parseFloat(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"float");break;
                        case 5:data = ByteUtils.getObjectTypeToByte((double) Double.parseDouble(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"double");break;
                        case 6:data = ByteUtils.getObjectTypeToByte((byte[])ByteUtils.hexStrToBytes(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText()),"byte");break;
                        case 7: break;//data =16进制00??01特征码数组  ;
                        case 8:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringUTF8None");break;
                        case 9:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringUniCodeNone");break;
                        case 10:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringAsciiNone");break;
                        case 11:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringUTF8");break;
                        case 12:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringUniCode");break;
                        case 13:data = ByteUtils.getObjectTypeToByte(PaneAndHBoxFrameAndColumnVBoxAndHBoxInputValueAndTextFieId.textField.getText(),"StringAscii");break;
                        case 14:break;//data = 未知的2字节
                        case 15:break;//data = 未知的4字节
                        case 16:break;//data = 未知的8字节
                        case 17:break;//data = 大于的数值
                        case 18:break;//data = 小于的数值
                        case 19:break;//data = 两数之间数值
                        case 20:break;//data = 未改变的数值
                        case 21:break;//data = 改变的数值
                    }
                    new Thread(new dataBuff()).start();
                }else {
                    SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"不能为空","温馨提示",0);
                    PaneAndHBoxFrameAndProgressBar.progressBar.setProgress(-1);
                }





            }
        });
    }
}
class dataBuff implements Runnable{
    @Override
    public void run() {
        if(StageWindowsProcessAndListView.ProcessIDHandle > 0){

            if(ModuleOperationUtilsJNI.systemIs32()){
                MemoryOperationUtilsX86.threadSearchMemory(ProcessAndThreadUtils.openProcess(ProcessAndThreadUtils.processNameGetPid("QQ.exe")), ByteUtils.getObjectTypeToByte(2,"int"),null);
            }





        }else {
            Platform.runLater(new Runnable() {
                @Override
                public void run() {
                    PaneAndHBoxFrameAndProgressBar.progressBar.setProgress(0f);
                }
            });
            SystemUtils.messageBoxExW(WindowOperationUtils.windowGetHwnd(),"请先打开进程否则无法进行内存搜索","温馨提示",0);
        }

    }
}

